<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台产品首页控制器
 * 主要获取产品相关页面信息
 */
class ProductsController extends HomeController {

	//新闻首页
    public function index(){
//        $this->assign('page',D('Document')->page);//分页

        //头部数据
        $wherenav=array(
            'language' => 0,
            'parentid' => 0
        );
        $nav=M('navigator')
            ->where($wherenav)
            ->order('sort')
            ->select();
        foreach ($nav as $key=>$value){
            $nav[$key]['list']=M('navigator')->where(array('parentid'=>$value['id']))->select();
        }
        $this->assign('nav',$nav);
        //头部数据
        //banner
        $banner=M('otherbanner')
            ->where(array('path'=>'/News/index'))
            ->find();
        $this->assign('banner',$banner['pictureid']);
        //banner

        //获取类别及列表内容

        $productcate=M('productcategory')
                    ->order('sort')
                    ->select();
//        var_dump($productcate);
        foreach ($productcate as $key=>$value){
            $productcate[$key]['list']=M('product')
                                        ->where(array('category'=>$value['id']))
                                        ->limit(4)
                                        ->select();
        }

        $this->assign('data',$productcate);
        $this->assign('empty','<li>暂无数据</li>');
        //获取类别及列表内容

//        var_dump($banner);
//        var_dump($productcate);exit;
//        var_dump($category);exit;
        $this->display();
    }
    public function showbyid(){
        //头部数据
        $wherenav=array(
            'language' => 0,
            'parentid' => 0
        );
        $nav=M('navigator')
            ->where($wherenav)
            ->order('sort')
            ->select();
        foreach ($nav as $key=>$value){
            $nav[$key]['list']=M('navigator')->where(array('parentid'=>$value['id']))->select();
        }
        $this->assign('nav',$nav);
        //头部数据
        //banner
        $banner=M('otherbanner')
            ->where(array('path'=>'/News/index'))
            ->find();
        $this->assign('banner',$banner['pictureid']);
        //banner
        $cateid=I('get.id');

        $name=M('productcategory')
            ->where(array('id'=>$cateid))
            ->find();
        $this->assign('name',$name);
        $data=M('product')
            ->where(array('category'=>$cateid))
            ->select();

        $this->assign('data',$data);

        $this->display();
    }

    public function detailbyid(){
        $id=I('get.id');
        //头部数据
        $wherenav=array(
            'language' => 0,
            'parentid' => 0
        );
        $nav=M('navigator')
            ->where($wherenav)
            ->order('sort')
            ->select();
        foreach ($nav as $key=>$value){
            $nav[$key]['list']=M('navigator')->where(array('parentid'=>$value['id']))->select();
        }
        $this->assign('nav',$nav);
        //头部数据
        //banner
        $banner=M('otherbanner')
            ->where(array('path'=>'/News/index'))
            ->find();
        $this->assign('banner',$banner['pictureid']);
        //banner
        $this->display();
    }
}